<?php
/**
 * Created by PhpStorm.
 * User: 钊鑫
 * Date: 2019/2/19
 * Time: 16:19
 */
namespace app\api\controller;

use Zzx\mail\PHPMailer;
use Zzx\mail\Exception;

class Mail
{
    public function sendMail()
    {
        $mail = new PHPMailer(true);                              // Passing `true` enables exceptions
        try {
            //qq: ggdtnjssjjbbbfbb,jenebvgowfkpbbfi
            //Server settings
            $mail->CharSet  = 'UTF-8'; //设定邮件编码，默认ISO-8859-1，如果发中文此项必须设置，否则乱码
            $mail->SMTPDebug = 0;                                 // Enable verbose debug output
            $mail->isSMTP();                                      // Set mailer to use SMTP
            $mail->Host = 'smtp.qq.com';                           // Specify main and backup SMTP servers
            $mail->SMTPAuth = true;                               // Enable SMTP authentication
            $mail->Username = '1064059707@qq.com';                 // SMTP username
            $mail->Password = 'jenebvgowfkpbbfi';                           // SMTP password
            $mail->SMTPSecure = 'ssl';                            // Enable TLS encryption, `ssl` also accepted
            $mail->Port = 465;                                    // TCP port to connect to

            //Recipients
            $mail->setFrom('1064059707@qq.com', 'Mailer');
            $mail->addAddress('13302516724@163.com', 'Joe User');     // Add a recipient
            $mail->addAddress('13302516724@163.com');               // Name is optional
            $mail->addReplyTo('info@example.com', 'Information');
            $mail->addCC('cc@example.com');
            $mail->addBCC('bcc@example.com');

            //Attachments
//            $mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
//            $mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name

            //Content
            $mail->isHTML(true);                                  // Set email format to HTML
            $mail->Subject = '测试主题';
            $mail->Body    = 'v1.0.0版本，会乱码吗，<b>会乱码吗</b>';
            //$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

            $mail->send();
            echo 'Message has been sent';
        } catch (Exception $e) {
            echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
        }
    }
}